package com.gxa.service.Impl;

import com.gxa.common.base.LayuiResultJson;
import com.gxa.common.base.Result;
import com.gxa.common.constant.Constants;
import com.gxa.domain.dto.MemberUpdateDto;
import com.gxa.domain.entity.Member;
import com.gxa.domain.vo.MemberVo;
import com.gxa.mapper.MemberMapper;
import com.gxa.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MemberServiceImpl implements MemberService {
    @Autowired
    private MemberMapper memberMapper;

    @Override
    public List<Member> chaXunAll(){
        List<Member> member = memberMapper.chaXunAll();
        return member;
    }

    @Override
    public Result xinZengById(Member member) {
        int result = memberMapper.xinZengById(member);
        if (result > 0 ){
            return Result.success("添加成功！");
        }
        return Result.error();
    }

    @Override
    public Result shanChuById(Integer id){
        int result = memberMapper.shanChuById(id);
        if (result > 0 ){
            return Result.success("删除成功！");
        }
        return Result.error();
    }

    @Override
    public Result gengXinById(MemberUpdateDto memberUpdateDto){
        int result = memberMapper.shanChuById(memberUpdateDto);
        if (result > 0 ){
            return Result.success("修改成功！");
        }
        return Result.error();
    }

    @Override
    public LayuiResultJson chaXunFenYe (Integer page,Integer limit){
        LayuiResultJson layuiResultJson = new LayuiResultJson();
        Integer offset = (page-1)*limit;
        Integer rows = limit;
        List<MemberVo> memberVos = memberMapper.chaXunFenYe(offset,rows);
        layuiResultJson.setCode(Constants.OK);
        layuiResultJson.setMsg(Constants.MESSAGE_OK);
        Integer totalSize = memberMapper.countMember();
        layuiResultJson.setCount(totalSize);
        layuiResultJson.setData(memberVos);
        return layuiResultJson;
    }
}
